package com.android.adapters;

import java.util.ArrayList;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ArrayAdapter;
import android.widget.TextView;

import com.android.R;
import com.android.entities.Event;
import com.android.search.OnItemClick;

public class ItemArrayAdapter extends ArrayAdapter<Event> {

    private ArrayList<Event> items;
    private Context mContext;
    
    public ItemArrayAdapter(Context context, int textViewResourceId, ArrayList<Event> items) {
            super(context, textViewResourceId, items);
            this.items = items;
            this.mContext = context;
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {    	
    	View v = convertView;
        if (v == null) {
            LayoutInflater vi = (LayoutInflater)mContext.getSystemService(Context.LAYOUT_INFLATER_SERVICE);
            v = vi.inflate(R.layout.row_item, null);
        }
        
        final Event event = items.get(position);
        if (event == null)
        	return v;
        
        TextView title = (TextView) v.findViewById(R.id.eventTitle);
        if (title != null)
             title.setText(event.getName());

        Intent mIntent = null;
        mIntent = new Intent();
        mIntent.putExtra("id", event.getId());
        mIntent.putExtra("name", event.getId());
        mIntent.putExtra("description", event.getId());
        mIntent.putExtra("category", event.getCategory());
        
        v.setOnClickListener(new OnItemClick(mContext, mIntent));

        return v;
    }
       
}